#version 150

in vec3 inVertex;
in vec2 inTexCoord;
in vec3 inNormal;

uniform vec3 inLightPos;

uniform mat4 inProj;
uniform mat4 inWorld;
uniform mat4 inView;

out vec2 geomTexCoord;
out vec3 geomLightPos;
out vec3 geomPosition;
out vec3 geomEyeDir;
out vec3 geomNormal;

void main()
{
    vec3 tangent;
	vec3 binormal;

	vec3 c1 = cross(inNormal, vec3(0.0, 0.0, 1.0));
	vec3 c2 = cross(inNormal, vec3(0.0, 1.0, 0.0));

	if(length(c1)>length(c2))
	{
		tangent = c1;
	}
	else
	{
		tangent = c2;
	}

	tangent = normalize(tangent);

	binormal = cross(inNormal, tangent);
	binormal = normalize(binormal);

	mat3 TBN = mat3 (tangent, binormal, inNormal);

	//---

    gl_Position = inProj * inView * inWorld * vec4(inVertex, 1);

    geomPosition = (inWorld * vec4(inVertex, 1)).xyz;

    geomLightPos = inLightPos;
    geomEyeDir = (-inView * vec4(inVertex, 1)).xyz;

    geomTexCoord = inTexCoord;

    geomNormal = inNormal;
}




















































































